/**
 * 一口价管理-城市配置
 * 文件命名格式：zmn.模块名称.表名称.功能.jas
 * @author heguanghua
 * @since 2018/10/18
 */
layui.define(['index', 'form', 'table', 'laypage', 'layedit', 'laydate', 'tooltipster'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var laypage = layui.laypage;
    var table = layui.table;

    // 省市区县下拉框联动
    zmnPage.laySelectLinkage(form, "/area/listCityList.action", "provinceId", "cityId");

    table.init('zmn-table', {
        toolbar: "#zmn-table-tool",
        page: true,
        limit: json.pageSize,
        defaultToolbar: ['filter'],
        height: 'full-189'
    });

    laypage.render(zmnPage.laypageOptions(json));

    // 【表格复选框监听】
    var ids = new Array();
    table.on("checkbox(zmn-table)", function () {
        ids = table.checkStatus('zmn-table').data.map((item) => item.relationId);
    });

    // 启用/停用
    table.on("toolbar(zmn-table)", function (obj) {
        if (obj.event == "start" || obj.event == "stop") {
            if (ids.length === 0) {
                return layer.alert("请选择至少一个要操作的记录！");
            }
            zmnPage.layStartStop(obj, "/pilot/city/updateStatus.action", ids.join(","));
        }
    });

    $(".btn-operate").click(function () {
        let relationId = $(this).attr("dataId");
        let html = "<div class='layui-btn-container'>" +
            "" + (json.hasViewEdit ? "<a lay-href='" + "/pilot/city/toEdit.action?relationId=" + relationId + "' class='layui-btn layui-btn-sm layui-btn-normal' lay-text='编辑' style='width:75px'>编辑</a>" : '') +
            "" + (json.hasViewEdit ? "<a lay-href='" + "/pilot/channel/price/serviceCategory.action?type=2&showType=2&configId=" + relationId + "' class='layui-btn layui-btn-sm layui-btn-normal' lay-text='应用分类' style='width:75px'>应用分类</a>" : '') +
            "" + (json.hasViewEdit ? "<a lay-href='" + "/pilot/city/detail.action?relationId=" + relationId + "' class='layui-btn layui-btn-sm layui-btn-normal' lay-text='详情' style='width:75px'>详情</a>" : '') +
            "" + (json.hasDel ? "<button onclick='deleteCityConfig(" + relationId + ")' class='layui-btn layui-btn-sm layui-btn-normal delete-city-config' lay-text='删除' style='width:75px'>删除</button>" : '') +
            "</div>";
        indexTips = layer.tips(html, this, {
            shade: [0],
            shadeClose: true,
            area: ['370px', '50px'],
            time: 0,
            tips: [3, '#FFFFFF'],
        });

    });

    exports('pilot_city_list', {});
});

// 根据id删除
function deleteCityConfig(id) {

    layer.confirm("确认删除吗?", function (index) {
        layer.close(index);
        zmnLayUtil.ajaxSimpleUE("/pilot/city/delete.action",
            {relationId: id}, null, function (json) {
                layer.msg(json.message);
                if (json.status == 200) {
                    document.forms[0].submit();
                }
            });
    });
}
